package com.zcoj.judgeServer.service.judge;

import com.zcoj.core.model.ApiResponse;
import com.zcoj.judgeServer.pojo.DTO.TestJudgeReq;
import com.zcoj.judgeServer.pojo.DTO.ToJudgeDTO;
import com.zcoj.judgeServer.service.JudgeServerEntityService;
import com.zcoj.judgeServer.service.JudgeService;
import com.zcoj.pojo.Dto.Judge;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

/**
 * @author chenbin
 * @version 1.0
 * @description: TODO
 * @date 2023/3/24 08:51
 */
@Component
public class OpenJudgeService {

 @Autowired
 private JudgeService judgeService;


 @Autowired
 private JudgeServerEntityService judgeServerEntityService;


 //查看判题机运行情况
 public ApiResponse getVersion() {
  return ApiResponse.success( "运行正常",judgeServerEntityService.getJudgeServerInfo());
 }


 //提交判题
 public ApiResponse submitProblemJudge(ToJudgeDTO toJudgeDTO) {
  Judge judge = toJudgeDTO.getJudge();
  if (judge == null || judge.getSubmitId() == null || judge.getUid() == null || judge.getPid() == null) {
   return ApiResponse.failed("调用参数错误！请检查您的调用参数！");
  }
  judgeService.judge(judge);
  return ApiResponse.success("判题机评测完成！",judge.getSubmitId());
 }


 //提交测试判题
 public ApiResponse submitProblemTestJudge(TestJudgeReq testJudgeReq) {
  if (testJudgeReq == null
          || StringUtils.isEmpty(testJudgeReq.getCode())
          || StringUtils.isEmpty(testJudgeReq.getLanguage())
          || testJudgeReq.getTimeLimit() == null
          || testJudgeReq.getMemoryLimit() == null
          || testJudgeReq.getStackLimit() == null) {
   return ApiResponse.failed("调用参数错误！请检查您的调用参数！");
  }
  return ApiResponse.success("测试完成",judgeService.testJudge(testJudgeReq));
 }
}